<template>
  <!-- <div class="chat-window">
    <Toolbar /> -->
   <div class="bg">
      <div class="main">
        <div class="main-top">
          <span>组件百分比</span>
          <span>日发电量(度)</span>
            <span>12.837 KWh</span>
        </div>
        <div class="main-tag">
          <span>组件百分比</span>
          <span>日发电量(度)</span>
            <span>12.837 KWh</span>
        </div>
      </div>

      <div class="canvas-container">
        <div
          class="canvas"
          :style="{
            ...getCanvasStyle(canvasStyleData),        
          }"
        >
          <ComponentWrapper v-for="(item, index) in copyData" :key="index" :config="item" />
        </div>
      </div>

    <div class="bottom">
     33
    </div>


     
    </div>
</template>

<script>
import { getStyle, getCanvasStyle } from '@/utils/style'
import { mapState } from 'vuex'
import ComponentWrapper from '@/components/Editor/ComponentWrapper'
import { changeStyleWithScale } from '@/utils/translate'
import { toPng } from 'html-to-image'
import { deepCopy } from '@/utils/utils'
import { im } from 'mathjs'
import jsonData from '@/store/myfile.json'; // 引入JSON文件

export default {
  components: { ComponentWrapper },
  props: {
    isScreenshot: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      copyData: jsonData,
    }
  },
  computed: mapState(['componentData', 'canvasStyleData']),
  created() {
console.log('this.componentData',this.jsonData)
        
//     this.$set(this, 'copyData', deepCopy(this.componentData))

  },
  methods: {
    getStyle,
    getCanvasStyle,
    changeStyleWithScale,

    close() {
      this.$emit('close')
    },

    htmlToImage() {
      toPng(this.$refs.container.querySelector('.canvas'))
        .then((dataUrl) => {
          const a = document.createElement('a')
          a.setAttribute('download', 'screenshot')
          a.href = dataUrl
          a.click()
        })
        .catch((error) => {
          console.error('oops, something went wrong!', error)
        })
        .finally(this.close)
    },
  },
}
</script>

<style lang="scss" scoped>
.main{
  display: flex;
  flex-direction: column;
  margin-top:40px ;
  left:0px ;
  position: absolute;
  width: 425px;
  font-size: 14px;
  color: rgba(26, 27, 29, 1);
  z-index: 9999;
}
.bottom{
  display: flex;
  flex-direction: column;
  margin-top:40px ;
  left:0px;
  position: absolute;
  width: 425px;
  font-size: 14px;
  color: rgba(26, 27, 29, 1);
  z-index: 9999;
  bottom: 30px;
height: 106px;
opacity: 1;
border-radius: 12px;
background: rgba(0, 0, 0, 0.12);

border: 1px solid rgba(194, 194, 194, 1);
}
.main-top{
  display: flex;
  justify-content: space-between; 
  font-weight: 500;
}
.main-tag{
  display: flex;
  font-size: 13.2px;
  font-weight: 400;
letter-spacing: 0px;
line-height: 18.48px;
color: rgba(102, 102, 102, 1);
  justify-content: space-between; 

  border-radius: 16.8px;
background: rgba(255, 255, 255, 1);
box-shadow: 0px 2px 7px 1px rgba(0, 0, 0, 0.08);
margin-top:20px;
padding: 20px

}

.chat-window {
    display: flex;
    flex-direction: column;
  overflow-y: auto; /* 允许纵向滚动 */
  }
.bg {
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  position: fixed;
//   background: rgb(0, 0, 0, 0.5);
  z-index: 10;
  display: flex;
//   align-items: center;
  justify-content: center;
  overflow: auto;
padding-bottom: 20px;
margin-left: 120px;

  .canvas-container {
    width: calc(100% - 40px);
    // height: calc(100% - 120px);
    overflow: auto;

    .canvas {
      background: #fff;
      position: relative;
      margin: auto;
    }
  }

  .close {
    position: absolute;
    right: 20px;
    top: 20px;
  }
}
  
</style>